package milu.dbxml.receipt;

import javax.xml.parsers.DocumentBuilder;

import milu.dbxml.DbXmlContext;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.sleepycat.dbxml.XmlValue;

public class DomRecipient implements Recipient {
	private final DbXmlContext dbxml;
	private final DocumentBuilder builder;
	private final Document dom;
	private final Element elm;

	public DomRecipient(DbXmlContext dbxml, DocumentBuilder builder,
			Document dom, Element elm) {
		this.dbxml = dbxml;
		this.builder = builder;
		this.dom = dom;
		this.elm = elm;
	}

	@Override public void receive(XmlValue value) {
		Document dom2 = dbxml.toDom(value, builder);
		elm.appendChild(
				dom.importNode(dom2.getDocumentElement(), true));
	}

}
